package Test;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class test3 {
    //力扣 771.宝石与石头
    public static void main(String[] args) {
        String jewels = "aA";
        String stones = "aaAbbb";
        System.out.println(numJewelsInStones2(jewels, stones));
    }
    //用set集合
    public static int numJewelsInStones(String jewels, String stones) {
        int count = 0;
        Set<Character> set = new HashSet<>();
        for(int i = 0;i<jewels.length();i++){
            set.add(jewels.charAt(i));
        }

        for (int i = 0; i < stones.length(); i++) {
            if(set.contains(stones.charAt(i))){
                count++;
            }
        }
        return count;
    }

    //用数组
    public static int numJewelsInStones2(String jewels, String stones) {
        int count = 0;
        int[] arr = new int[128];
        for (char c : jewels.toCharArray()){
            arr[c]=1;
        }

        for (char c :stones.toCharArray()) {
            count = count + arr[c];
        }
        return count;
    }

}
